﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class InternationalCup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.InternationalCup_PageTitle;
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("Default.aspx");
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            if (ou.TeamId == "Null")
                Response.Redirect("~/GeneralMessage.aspx?MessageString=M74ggdizz5wfeh");

            Boolean CupIsOver = false;

            string Season = "0";
            if (Request.QueryString["Season"] != null)
                Season = Request.QueryString["Season"].ToString();
            if (Season == "0")
                Season = (GND.ReadNivdalIntData("Nivdal_GetCurrentInternationalCupSeason"));

            CupIsOver = (GND.ReadNivdalBoolData("@Season", "Nivdal_IsInternationalCupOver", Season));
            //this.InternationalCupWinnersGridView.Visible = CupIsOver;
            this.InternationalCupTeamsLeftByCountryGridView.Visible = !CupIsOver;
            if (!IsPostBack)
            {
                this.InternationalCupSqlDataSource.SelectParameters.Add("Season", Season);
                this.InternationalCupSqlDataSource.SelectParameters.Add("Language", ou.Language);
                this.SeasonSqlDataSource.SelectParameters.Add("Language", ou.Language);
                this.InternationalCupWinnersSqlDataSource.SelectParameters.Add("Language", ou.Language);
            }
            this.InternationalCupFixturesLinkButton.NavigateUrl = "InternationalCupFixtures.aspx?season=" + Season;
            //Response.Write(Season);
            this.TeamsLeftTitleLabel.Visible = (this.InternationalCupTeamsLeftByCountryGridView.Rows.Count > 0);

        }

        protected void SeasonDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.InternationalCupSqlDataSource.SelectParameters.Clear();
            this.InternationalCupSqlDataSource.SelectParameters.Add("Season", this.SeasonDropDownList.SelectedValue);
            this.InternationalCupFixturesLinkButton.NavigateUrl = "InternationalCupFixtures.aspx?season=" + this.SeasonDropDownList.SelectedValue + "&round=" + 0;
        }


        public bool IsCupIsOver(Object obj)
        {
            if (obj.ToString() == "False")
            {
                //Response.Write(obj.ToString());
                return false;
            }
            else
                return true;
        }

        public bool IsTeam(Object obj)
        {
            if (obj.ToString() == "0")
            {
                //Response.Write(obj.ToString());
                return false;
            }
            else
                return true;
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}